package com.shenyi.mould.rest.controller.wx;

import com.alibaba.fastjson.JSONObject;
import com.shenyi.core.cache.J2CacheUtils;
import com.shenyi.wx.annotation.LoginUser;
import com.shenyi.wx.entity.BuyGoodsDO;
import com.shenyi.wx.entity.UserDO;
import com.shenyi.wx.util.ApiBaseAction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author richard.fan
 * @version 1.0
 * @date 2018/11/07
 * @desc 购买
 * @see
 * @since 1.0
 */
@Api(tags = "商品购买")
@RestController
@RequestMapping("/api/buy")
public class ApiBuyController extends ApiBaseAction {


    @Autowired
    private J2CacheUtils j2CacheUtils;

    @ApiOperation(value = "商品添加")
    @PostMapping("/add")
    public Object addBuy(@LoginUser UserDO loginUser) {
        JSONObject jsonParam = getJsonRequest();
        Integer goodsId = jsonParam.getInteger("goodsId");
        Integer productId = jsonParam.getInteger("productId");
        Integer number = jsonParam.getInteger("number");
        BuyGoodsDO GoodsDO = new BuyGoodsDO();
        GoodsDO.setGoodsId(goodsId);
        GoodsDO.setProductId(productId);
        GoodsDO.setNumber(number);
        j2CacheUtils.put(J2CacheUtils.SHOP_CACHE_NAME, "goods" + loginUser.getUserId() + "", GoodsDO);
        return toResponsMsgSuccess("添加成功");
    }
}
